package com.bo.exception;

import java.io.PrintStream;
import java.io.PrintWriter;

public class AppException extends Exception {

	private static final long serialVersionUID = -3620827757855210270L;
	private Throwable rootcause;
//	private Object[] args;
	private String code;
	
public String getCode()
    {
        return code;
    }
    public void setCode(String code)
    {
        this.code = code;
    }
    //	public Object[] getArgs() {
//		return args;
//	}
//	public void setArgs(Object[] args) {
//		this.args = args;
//	}
	public Throwable getRootcause() {
		return rootcause;
	}
	public AppException(String message) {
		super(message);
	}

//	public AppException(String message,Object... args) {
//		super(message);
//		this.args = args;
//	}

	public AppException(String code,String message) {
		super(message);
		this.code = code;
	}
	public AppException(Throwable cause) {
		rootcause = cause;
	}

	public AppException(String code, Throwable cause) {
		this.code = code;
		rootcause = cause;
	}

//	public AppException(String message, Throwable cause,Object... args) {
//		super(message);
//		rootcause = cause;
//		this.args = args;
//	}

	public String getMessage() {
		if (rootcause == null)
			return super.getMessage();
		else
			return super.getMessage() + "; cause exception is: \n\t"
					+ rootcause.toString();
	}

	public void printStackTrace() {
		printStackTrace(System.err);
	}

	public void printStackTrace(PrintStream s) {
		if (rootcause == null) {
			super.printStackTrace(s);
		} else {
			s.println(this);
			rootcause.printStackTrace(s);
		}
	}

	public void printStackTrace(PrintWriter s) {
		if (rootcause == null) {
			super.printStackTrace(s);
		} else {
			s.println(this);
			rootcause.printStackTrace(s);
		}
	}

}
